package com.lanxin.oa.zu.dao.daoImpl;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.MpCardtype;
import com.lanxin.bean.MpContact;
import com.lanxin.oa.zu.dao.ZuDao;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;

@Repository
public class ZuDaoImpl extends BaseDaoImpl implements ZuDao {

    @Override
    public PageBean<MpCardtype> selectzu(Integer page, Integer pageSize,String type) {
        if(page==null){
            page=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        String hql="from MpCardtype zu where 1=1";
        if(type !=null && !type.equals("")){
            hql = hql + "  and zu.type = '" + type + "'  ";
        }
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public MpCardtype selectzuByid(Integer oid) {
        return (MpCardtype)super.getById(MpCardtype.class,oid);
    }

    @Override
    public MpCardtype selectzuBytype(String type,Integer oid) {
        String hql = "from MpCardtype zu where zu.type='" + type + "' ";
        MpCardtype zu = null;
        if (oid != null) {
            hql = hql + " and zu.oid=" + oid;
            zu = (MpCardtype) selectByHQL(hql);
            if (zu != null) {
                return null;
            }
            zu = (MpCardtype) selectByHQL("from MpCardtype zu where zu.type='" + type + "' ");
            if (zu == null) {
                return null;
            }
        } else {
            return (MpCardtype) selectByHQL(hql);
        }

        return zu;
    }

    @Override
    public MpContact selectmp(Integer typeid) {
        return (MpContact)super.selectByHQL("from MpContact mp where mp.typeid="+typeid);
    }
}
